<?php

/**
 * @author chenyun
 * 百大-海恒达
 */
namespace App\Service\OrderService\OrderRouteService;
use App\Service\Code\Normal;
use App\Service\OrderService\BaseSupplierRouterService;
use App\Service\TraitService\SupplierRouterOrderTrait;
use App\Service\VendorClient\ShophaihengdaApi\ShophaihengdaApiClient;
use App\Model\CommodityModel\Hscodeinfo;

class Shophaihengda extends BaseSupplierRouterService
{
    use SupplierRouterOrderTrait;
    
    /**
     * 订单申报
     * @param array $param
     * @return mixed
     */
    public function orderPay( $param = [] )
    {
        $declare_hscodes = array_column($param['orderGoods'],'declare_hscode');
        $SupplierSkuCodes = array_column($param['orderGoods'],'supplier_skucode');
        $SupplierID = $param['companyInfo']["company_id"];
        if(empty($declare_hscodes)){
            return Normal::returnCode(Normal::FAIL,"当前订单商品hscode不能为空，请核实！");
        }
        $hscode_map = Hscodeinfo::instance()->whereIn('Code',$declare_hscodes)->whereIn('SupplierSkuCode',$SupplierSkuCodes)->where("SupplierID",$SupplierID)->select()->get()->toArray();
        if(empty($hscode_map)){
            return Normal::returnCode(Normal::FAIL,"没有查询该订单商品的hscode相关信息，请核实！");
        }
        $hscode_map_list = [];
        foreach ($hscode_map as $k =>$hscode){
            $hscode_map_list[$hscode["SupplierSkuCode"]] = $hscode;
        }
        $param['hscode_map_list'] = $hscode_map_list;
        return $this->callSdkApi(ShophaihengdaApiClient::class,$param['apiBody'])->createOrder($param);
    }

    /**
     * 订单取消
     * @param array $param
     * @return mixed
     */
    public function orderCancel( $param = [] )
    {
        return Normal::returnCode(Normal::SUC,"处理完成");
    }
    
    /**
     * 订单售后
     * @param array $param
     * @return mixed
     */
    public function orderAfterSale($param = [])
    {
        return $this->callSdkApi(ShophaihengdaApiClient::class,$param['apiBody'])->cancelOrder($param);
    }
    
    /**
     * 获取物流信息
     * @param array $param
     */
    public function orderExpress( $param = [] )
    {
        return Normal::returnCode(Normal::SUC,"处理完成");
    }

    /**
     * 商品列表查询接口
     * @param array $param
     * @return mixed
     */
    public function queryGoodsList( $param = [] )
    {
        return Normal::returnCode(Normal::SUC,"处理完成");
    }
}